-- DelayAction
-- Created by chengb May/13/2015
-- 延迟动作

-- TODO 飞行速度
local speed = 800;

DelayAction = class("DelayAction", function()
    return ActionBase.create();
end);

function DelayAction.create(source, target, delay)
    local self = DelayAction.new();
    self.source = source;
    self.target = target;
    self.delay = delay;
    return self;     
end

-- 构造函数
function DelayAction:ctor()
end

-- 开始播放
function DelayAction:play()
    local delay = self.delay or 0;
       
    if delay ~= nil and delay > 0 then
        return delay;
    end   
       
    if self.source.type == OBJECT_TYPE_SUMMON then
        -- 召唤兽自爆 TODO 获取自爆动画长度
        delay = 1;
    elseif self.target.type == OBJECT_TYPE_MONSTER then
        -- 怪物受创
        local toPos = UIDungeonMgr:getCurLevel():getMonsterPos(self.target:getOwner());
        
        local fromPos = UIDungeonMgr:getCurLevel():getGridPos(self.source:getPos());

        local distance = cc.pGetDistance(fromPos, toPos);

        -- TODO 速度需要从配置中读取（暂时用的是排炮的速度）
        delay = distance / (3.0*speed);
            
    elseif self.target.type == OBJECT_TYPE_USER then
        -- 玩家受创
        -- TODO
    end
        
    return delay;
end

return DelayAction;
